
from datetime import datetime

#引用 MongoEngine的实例
from app import  db


NEWS_TYPES =(
    ('推荐', '推荐'),
    ('百家', '百家'),
    ('本地', '本地'),
    ('图片', '图片')
)

'''定义新闻模型'''
class News(db.Document):
    title =   db.StringField(required=True, max_length=200)
    img_url = db.StringField()
    content = db.StringField()
    is_valid = db.BooleanField(default=True)
    created_at = db.DateTimeField(default=datetime.now())
    updated_at = db.DateTimeField(default=datetime.now())
    news_type = db.StringField(required=True, choices=NEWS_TYPES)

    meta = {
        'collection': 'news',
        'ordering': ['-created_at']  #排序--倒序
    }

    def __repr__(self):
        return '<News %r>' % self.title
